package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.treasure.TreasureActivityPlace;
import com.yanqu.road.entity.activity.treasure.TreasurePlaceProgressInfo;
import com.yanqu.road.entity.activity.treasure.UserTreasureActivityData;
import com.yanqu.road.pb.treasureactivity.TreasureActivityProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.treasure.TreasureActivityMgr;

import java.util.ArrayList;
import java.util.List;

public class TreasureActivityPb {
    public static TreasureActivityProto.UserTreasureDataTemp.Builder parseUserDataTempBuilder(UserTreasureActivityData userActivityData, int hasTimes, TreasurePlaceProgressInfo placeProgressInfo) {
        TreasureActivityProto.UserTreasureDataTemp.Builder builder = TreasureActivityProto.UserTreasureDataTemp.newBuilder();
        builder.setActivityId(userActivityData.getActivityId());
        builder.setScore(userActivityData.getScore());
        builder.setTaskProgress(userActivityData.getTaskProgress());
        builder.setRewordRound(userActivityData.getRewardRound());

        builder.setPlaceId(placeProgressInfo.getPlaceId());
        builder.setRouteProgress(placeProgressInfo.getRoutProgress());
        builder.setCurrentRound(placeProgressInfo.getRound());
        builder.setHasTimes(hasTimes);
        return builder;
    }

    public static TreasureActivityProto.TreasurePlaceConfig.Builder parsePlaceConfigMsg(int activityId, List<TreasureActivityPlace> list,String language) {

        TreasureActivityProto.TreasurePlaceConfig.Builder builder = TreasureActivityProto.TreasurePlaceConfig.newBuilder();
        builder.setActivityId(activityId);
        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
        if (activityInfo != null) {
            builder.setRoundTokenRewardNum(TreasureActivityMgr.getActivityRoundTokenReward(activityInfo));
        }
        if (list != null && list.size() > 0) {
            builder.addAllPlaceConfigTemp(parsePlaceTemp(list,language));
        }
        return builder;
    }

    private static List<TreasureActivityProto.PlaceConfigTemp> parsePlaceTemp(List<TreasureActivityPlace> list,String language) {
        List<TreasureActivityProto.PlaceConfigTemp> resultList = new ArrayList<>();
        for (TreasureActivityPlace place : list) {
            TreasureActivityProto.PlaceConfigTemp.Builder builder = TreasureActivityProto.PlaceConfigTemp.newBuilder();
            builder.setPlaceId(place.getId());
            builder.setPlaceName(ServerLanguageMgr.getContent(place.getName(),language));
            builder.setPlaceDesc(ServerLanguageMgr.getContent(place.getDesc(),language));
            builder.setPlaceIcon(place.getIcon());
            builder.setRewardBox(place.getRewardBox());
            builder.setEventDesc(ServerLanguageMgr.getContent(place.getEventDesc(),language));
            builder.setPlaceCoordinate(place.getPlaceCoordinate());
            builder.setRouteCoordinate(place.getRouteCoordinateLists());
            builder.setTokenRewards(place.getTokenRewards());
            resultList.add(builder.build());
        }
        return resultList;
    }
}
